package com.briup.mt.service.impl;

import com.briup.mt.bean.Interfaces;
import com.briup.mt.bean.InterfacesExample;
import com.briup.mt.dao.InterfacesMapper;
import com.briup.mt.service.IInterfacesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author yks
 * @version 1.0
 * @date 2020/12/17 9:22
 */
@Service
public class InterfacesServiceImpl implements IInterfacesService {

    @Resource
    private InterfacesMapper interfacesMapper;

    @Override
    public List<Interfaces> query(String name, String status) {
        InterfacesExample example = new InterfacesExample();
        if (!StringUtils.isEmpty(name)) {
            example.createCriteria().andNameLike("%" + name + "%");
        }
        if (!StringUtils.isEmpty(status)) {
            example.createCriteria().andStatusEqualTo(status);
        }
        List<Interfaces> list = interfacesMapper.selectByExample(example);
        return list;
    }

    @Override
    public void saveOrUpdate(Interfaces interfacs) {
        if (interfacs.getId() == null) {
            interfacesMapper.insert(interfacs);
        } else {
            interfacesMapper.updateByPrimaryKey(interfacs);
        }
    }

    public void deleteById(long id){
        interfacesMapper.deleteByPrimaryKey(id);
    }
}
